package LuoGu;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.StreamTokenizer;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;

public class P1102Plus {
    public static void main(String[] args) throws IOException {
        StreamTokenizer st=new StreamTokenizer(new BufferedReader(new InputStreamReader(System.in)));
        st.nextToken();
        int arrLen=(int)st.nval;
        st.nextToken();
        int c=(int)st.nval;
        HashMap<Integer, Long> map=new HashMap<>();
        int sum=0;
        int indexA=0;
        for (int i = 0; i < arrLen; i++) {
            st.nextToken();
            int tmp2=(int)st.nval;
            if(map.containsKey(tmp2)){
                map.put(tmp2,map.get(tmp2)+1);
            }else{
                map.put(tmp2, 1L);
            }
        }
        int[] data=new int[map.size()];
        for (Map.Entry<Integer, Long> integerLongEntry : map.entrySet()) {
            data[indexA]=integerLongEntry.getKey();
            indexA++;
        }
        Arrays.sort(data);
        for (int i = 0; i < data.length; i++) {
            int tmp = data[i] + c;
            int index=Arrays.binarySearch(data, tmp);
            if (index>=0) {
                sum += map.get(data[index]) * map.get(data[i]);
            }
        }
        System.out.print(sum);
    }
}
